//
//  UIAnimationViewController.swift
//  DemoUI
// 动画相关
//  Created by 白瑾浩 on 2022/1/10.
//

import UIKit

class UIAnimationViewController: UIViewController {
    var animationView:UIView?
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = .white
        title = "动画相关的界面"
        //实例1
//        animationView = UIView(frame: CGRect(x: 100, y: 100, width: 100, height: 100))
//
//        animationView?.backgroundColor = UIColor.red
//
//        self.view.addSubview( animationView! )
//
//
        //实例2
        
        animationView = UIView(frame: CGRect(x: 100, y: 100, width: 100, height: 100))
        animationView?.backgroundColor = UIColor.red
        self.view.addSubview( animationView! )
        
        //图片动画 插值
        
        
        
        
        
        
        
        
        
    }
    //当点击屏幕 下面的背景改变
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        
        //实例1
//        UIView.animate(withDuration: 1) {
//            self.animationView?.backgroundColor = UIColor.green
//        }
        //先渐变颜色
//        UIView.animate(withDuration: 2,animations: {
//            self.animationView?.backgroundColor = UIColor.blue
//
//        }){(finish) in
//            //平移到指定坐标
//            UIView.animate(withDuration: 2) {
//                self.animationView?.center = CGPoint(x: 150, y: 300)
//            }
//        }
        //动画延时配置相关   .repeat 重复执行 .autoreverse 自动 逆向执行动画 然后完成
//        UIView.animate(withDuration: 1, delay: 1, options: [UIView.AnimationOptions.transitionCurlDown], animations: {
//            self.animationView?.backgroundColor = UIColor.blue
//        }, completion: nil)
        //usingSpringWithDamping 阻尼效果 initialSpringVelocity 初始速度 都是0~1
//        UIView.animate(withDuration: 2, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0.5, options: [UIView.AnimationOptions.transitionCurlDown], animations: {
//            self.animationView?.center = CGPoint(x: 300, y: 400)
//        }) { (b) in
//            print( "完成" )
//        }
        
        //实例2
//        UIView.transition(with: animationView!, duration: 2, options: UIView.AnimationOptions.transitionFlipFromTop,animations: {
//            print("我要翻转了")
//        }){ (b) in
//            print("执行完成\(b)")
//        }
//
        let otherView = UIView(frame: CGRect(x: 100, y: 100, width: 100, height: 100))
        otherView.backgroundColor = UIColor.blue
        
        UIView.transition(from: animationView!, to: otherView, duration: 2, options: UIView.AnimationOptions.transitionFlipFromRight
        ){ (b) in
                print( "执行完成" )
        }
        
    }

}
